import { zhejiangProvinceAdInfo } from '@/mixins/mapMixinsData';
import { defSet, getStyleStr } from '@/components/masking/maskSeting.vue';

let boundsMap = {};
try {
  boundsMap = JSON.parse(localStorage.getItem('boundsMap')) || {};
} catch (e) {
  console.log('首次初始化，没有找到历史数据！');
}

const state = {
  adcode: zhejiangProvinceAdInfo.adcode,
  areaIds: '[1]',
  // adLevel: zhejiangProvinceAdInfo.level,
  adInfo: zhejiangProvinceAdInfo,
  homeMapMask: getStyleStr(defSet.homeMapMask),
  boundsMap: boundsMap
  // subsidyRows: {}
};
const mutations = {
  SET_AD_CODE (state, param) {
    state.adcode = param;
  },
  SET_AD_IDS (state, param) {
    state.areaIds = param;
  },
  SET_AD_INFO (state, param) {
    state.adInfo = param;
  },
  SET_AD_LEVEL (state, n) {
    state.adLevel = n;
    if (n === 1) {
      state.adId = null;
    }
    if (n === -1) {
      // TODO 当地图是多级时，这里寻找目标code
      state.adcode = state.adInfo.parent.adcode;
    }
  },
  SET_MASK_VALUES (state, param) {
    state.homeMapMask = param;
  },
  SET_BOUNDS (state, param) {
    const { id, bounds } = param;
    state.boundsMap[id] = bounds;
    localStorage.setItem('boundsMap', JSON.stringify(state.boundsMap));
  }
  // SET_SUBSIDY_ROWS(state, param) {
  //   state.subsidyRows = param
  // }
};
const actions = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
